#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <math.h>

double S,E,r,sigma,T;
int iter;

#define TWO_PI 6.2831853071795864769252866
const int qntThreads = 1;
const int MAX_R = 32767;

typedef struct args args;
struct args
{
	int iter;
	int id;//id da thread
	long long next;//semente
	double * trials;//vetor de tentativas
};

int randi(long long * next) 
{
    (*next) = (*next) * 1103515245 + 12345;
    return((unsigned)((*next)/65536) % 32768);
}

double doubleRandi(long long *next)
{
	return (double)randi(next)/MAX_R;
}

 
double generateGaussianNoise(long long *next)//gerador normal
{
	static int haveSpare = 0;
	static double rand1, rand2;
	static double variance = 1;
 
	if(haveSpare)
	{
		haveSpare = 0;
		return sqrt(variance * rand1) * sin(rand2);
	}
 
	haveSpare = 1;
 
	rand1 = randi(next) / ((double) MAX_R);
	if(rand1 < 1e-100) rand1 = 1e-100;
	rand1 = -2 * log(rand1);
	rand2 = (randi(next) / ((double) MAX_R)) * TWO_PI;
 
	return sqrt(variance * rand1) * cos(rand2);
}

double max(double a, double b)
{
	return (a > b) ? a : b;
}

void * solve(void * param)
{
	args * xarg = (args *) param;

	int i;
	for (i = 0; i < xarg->iter; ++i)
	{
		double p1 = (r -  0.5 * sigma * sigma) * T;
		double p2 = sigma * sqrt(T) * generateGaussianNoise(&(xarg->next));
		double t = S * pow((double)M_E, p1 + p2);

		xarg->trials[i] = pow((double)M_E, -r * T) * max(t-E, 0);
	}
}

int main (void)
{
	args vargs[qntThreads + 1];
	pthread_t threads[qntThreads + 1];
	int i;

	scanf("%lf %lf %lf %lf %lf %d",&S, &E, &r, &sigma, &T, &iter);

	for (i = 0; i < qntThreads; ++i)
	{
		vargs[i].iter = iter/qntThreads;
		vargs[i].id = i;
		vargs[i].next = (i + 100);
		vargs[i].trials = (double *) malloc ((iter + qntThreads - 1) * sizeof(double));
		pthread_create( &threads[i], NULL, solve, (void*)(&vargs[i]));
	}

	double mean = 0, variance = 0, stddev = 0;
	double qnt = 0;

	for (i = 0; i < qntThreads; ++i)
	{
		pthread_join(threads[i], NULL);
		
		int j;
		for (j = 0; j < vargs[i].iter; ++j)
			mean += vargs[i].trials[j];

		qnt += vargs[i].iter;
	}

	mean = mean/qnt;

	for (i = 0; i < qntThreads; ++i)
	{
		int j;
		for (j = 0; j < vargs[i].iter; ++j)
		{
			variance += (vargs[i].trials[j] - mean) * (vargs[i].trials[j] - mean);
		}
	}

	variance /= qnt;
	
	stddev = sqrt(variance);

	double confwidth = 1.96 * (stddev/sqrt(iter));
	double confmin = mean - confwidth;
	double confmax = mean + confwidth;

	printf("S        %.1lf\nE        %.1lf\nr        %.1lf\nsigma    %.1lf\nT        %.1lf\nM        %d\nConfidence interval: (%.1lf, %.1lf)\n",S,E,r,sigma,T,iter,confmin,confmax);
	return 0;
}